package com.taoyibao.hongcanting.ui.mine.activity;

import android.os.Bundle;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.activity.BaseActivityPresenter;
import com.taoyibao.hongcanting.base.delegate.BackViewPageDelegate;
import com.taoyibao.hongcanting.constant.CodeConstant;
import com.taoyibao.hongcanting.event.EventFinishActivity;
import com.taoyibao.hongcanting.ui.mine.fragment.MineOrderFragment;
import com.taoyibao.hongcanting.utils.CodeUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @author TangAnna
 * @description: 我的订单
 * @date :${DATA} 14:05
 */
public class MineOrderActivity extends BaseActivityPresenter<BackViewPageDelegate> {

    @Override
    protected Class<BackViewPageDelegate> getDelegateClass() {
        return BackViewPageDelegate.class;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        viewDelegate.setFragmentManager(getSupportFragmentManager());
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void bindEvenListener() {
        super.bindEvenListener();
        EventBus.getDefault().register(this);
        viewDelegate.setTitle("我的订单");
        viewDelegate.addViewPageTab("全部", MineOrderFragment.getInstance(CodeConstant.ORDER_STATUS_All));
        viewDelegate.addViewPageTab("待支付", MineOrderFragment.getInstance(CodeConstant.ORDER_STATUS_NOPAY));
        viewDelegate.addViewPageTab("已完成", MineOrderFragment.getInstance(CodeConstant.ORDER_STATUS_COMPLETED));
        viewDelegate.setTabLayoutBackgroundColor(CodeUtils.getIdColor(R.color.colorBg));
    }

    /**
     * 订单支付成功之后收消息关闭页面
     *
     * @param event
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void EventFinish(EventFinishActivity event) {
        if (event.paySuccess) {
            finish();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
